import os
# https://hf-mirror.com/models
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
from transformers import pipeline

# 初始化文本分类pipeline
classifier = pipeline(
    'text-classification',
    model='distilbert-base-uncased-finetuned-sst-2-english'
)

def analyze_sentiment(text):
    """
    情感分析函数
    Args:
        text (str): 待分析的文本
    Returns:
        dict: 包含预测标签和置信度的字典
    """
    result = classifier(text)[0]
    return {
        'label': result['label'],
        'score': result['score']
    }

if __name__ == '__main__':
    test_text = "I love programming with Python!"
    print(analyze_sentiment(test_text))
    print("execute success")